package cn.iocoder.yudao.framework.common.util.spring;

import org.springframework.context.ApplicationContext;

/**
 * 获取对象工具类
 */
public class SpringContextUtils {

    private static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }

    public static ApplicationContext getApplicationContext(){
        return applicationContext;
    }

    public static <T> T getBean(String beanId){
        return (T) getApplicationContext().getBean(beanId);
    }

    public static <T> T getBean(Class<T> type){
        return getApplicationContext().getBean(type);
    }
}
